/**
 * 
 */
package leetCode;

/**
 * @author zhongfang
 *
 */
public class FindPivotIndex {
	public int pivotIndex(int[] nums) {
		int n = nums.length;
		int[] left = new int[n];
		int totalSum = 0;
		for (int i = 0; i < n; i++) {
			totalSum += nums[i];
			left[i] = totalSum;
		}
		for (int i = 0; i < n; i++) {
			if (left[i] == totalSum - left[i] + nums[i]) {
				return i;
			}
		}
		return -1;
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		int[] nums = { 1, -1, -3 };
		System.out.println(new FindPivotIndex().pivotIndex(nums));
	}

}
